package com.bclz.task.groupcomparing;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class Order implements WritableComparable<Order> {
			
	private String orderId;
	
	private String userId;
	
	private String price; 
	
	private String productName;
	
	public Order() {}
	

	public Order(String orderId, String userId, String price, String productName) {
		this.orderId = orderId;
		this.userId = userId;
		this.price = price;
		this.productName = productName;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	@Override
	public void write(DataOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeUTF(this.orderId);
		out.writeUTF(this.userId);
		out.writeUTF(this.productName);
		out.writeUTF(this.price);
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		// TODO Auto-generated method stub
		this.orderId=in.readUTF();
		this.userId=in.readUTF();
		this.productName=in.readUTF();
		this.price=in.readUTF();
	}

	@Override
	public int compareTo(Order o) {
		// TODO Auto-generated method stub
		return this.getOrderId().compareTo(o.getOrderId())==0?this.getPrice().compareTo(o.getPrice()):this.getOrderId().compareTo(o.getOrderId());
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return String.format("order:%s - user:%s - price:%s", this.orderId!=null?this.orderId:"无",this.userId!=null?this.userId:"无",this.price!=null?this.price:0f);
	}
	
}
